//
//  main.swift
//  203-移除链表元素
//
//  Created by lhc on 2023/9/14.
//

import Foundation

let l1 = [1, 2, 6, 3, 4, 5, 6]
let val1 = 6
let l2 = Array(repeating: 7, count: 3)
let val2 = 7
let l3 = [Int]()

func test(l: [Int], val: Int, fun: (ListNode<Int>?, Int) -> ListNode<Int>?) {
    let node = ListNode.initWithList(l: l)
    guard let node = node else {
        print("before: nil")
        return
    }
    print("before: \(node)")
    guard let result = fun(node, val) else{
        print("after: nil")
        return
    }
    print("after: \(result)")
}


print("----------cycle----------")
test(l: l1, val: val1, fun: Solution.removeElements(_:_:))
test(l: l2, val: val2, fun: Solution.removeElements(_:_:))
test(l: l3, val: val2, fun: Solution.removeElements(_:_:))
print("----------recursion----------")
test(l: l1, val: val1, fun: Solution.removeElementsByRecurison(_:_:))
test(l: l2, val: val2, fun: Solution.removeElementsByRecurison(_:_:))
test(l: l3, val: val2, fun: Solution.removeElementsByRecurison(_:_:))

